{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "zxYRBzET4SNe",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    import evidently\n",
    "except:\n",
    "    get_ipython().system('pip install git+https://github.com/evidentlyai/evidently.git')"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "from sklearn import datasets, ensemble, model_selection\n",
    "\n",
    "from evidently import ColumnMapping\n",
    "from evidently.report import Report\n",
    "from evidently.metrics import RegressionQualityMetric\n",
    "from evidently.metrics import RegressionPredictedVsActualScatter\n",
    "from evidently.metrics import RegressionPredictedVsActualPlot\n",
    "from evidently.metrics import RegressionErrorPlot"
   ],
   "metadata": {
    "id": "jB-t9Hqu4iOJ",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "housing_data = datasets.fetch_california_housing(as_frame=True)\n",
    "housing = housing_data.frame\n",
    "\n",
    "housing.rename(columns={'MedHouseVal': 'target'}, inplace=True)\n",
    "housing['prediction'] = housing_data['target'].values + np.random.normal(0, 3, housing.shape[0])\n",
    "\n",
    "housing_ref = housing.sample(n=5000, replace=False, random_state=0)\n",
    "housing_cur = housing.sample(n=5000, replace=False, random_state=0)"
   ],
   "metadata": {
    "id": "ywrXgFg64iRb",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "By default, our reports feature aggregated plots"
   ],
   "metadata": {
    "id": "yDE8TG8r4-1E",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "report = Report(metrics=[\n",
    "    RegressionQualityMetric(),\n",
    "    RegressionPredictedVsActualScatter(),\n",
    "    RegressionPredictedVsActualPlot()\n",
    "])\n",
    "report.run(reference_data=housing_ref, current_data=housing_cur)\n",
    "report"
   ],
   "metadata": {
    "id": "zB6iMHT25tAX",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "To change this behavior, you can use render options. \n",
    "\n",
    "You can apply changes to the entire report:"
   ],
   "metadata": {
    "id": "poRhh0CE6T-6",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "report = Report(\n",
    "    metrics=[\n",
    "      RegressionQualityMetric(),\n",
    "      RegressionPredictedVsActualScatter(),\n",
    "      RegressionPredictedVsActualPlot()\n",
    "    ],\n",
    "    options={\"render\": {\"raw_data\": True}}\n",
    "  )\n",
    "report.run(reference_data=housing_ref, current_data=housing_cur)\n",
    "report"
   ],
   "metadata": {
    "id": "Hy8m_jdF6UOd",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "or to individual metrics:"
   ],
   "metadata": {
    "id": "FriAPDJh7Onu",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "report = Report(\n",
    "    metrics=[\n",
    "      RegressionQualityMetric(),\n",
    "      RegressionPredictedVsActualScatter(options={\"render\": {\"raw_data\": True}}),\n",
    "      RegressionPredictedVsActualPlot()\n",
    "    ],\n",
    "  )\n",
    "report.run(reference_data=housing_ref, current_data=housing_cur)\n",
    "report"
   ],
   "metadata": {
    "id": "R5YEvhNX5_hM",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [],
   "metadata": {
    "id": "ZhMC7G-V7W5e",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 6,
   "outputs": []
  }
 ]
}
